define(function(require){
	var main = require('/static/main.js');
	var m = new main();

	var type = {
		'7' : {isfirst:true},
		'14' : {isfirst:true},
		'30' : {isfirst:true},
	}
	var numCount = true;
	function Cont(){
		this.Fun._init();
	}
	Cont.prototype.Fun = {
		_init:function(){
			// 初始化左边菜单
			this.getdetialData(7);
			this.bindEvent();
		},
		bindEvent:function(){
			var _this = this;
			$(document).on('click','.nav-tabs li a',function(){
				var count = parseInt($(this).attr('data-first'));
				_this.getdetialData(count);
			})
		},
		getdetialData:function(count){
			if(!type[count].isfirst){
				return false;
			}
			var _this = this;
			$.ajax({
                type: "POST",
                url: "/analysis/get-detial",
                data: {Range:count},  
                dataType: "json",
                success: function (ret) {
                   type[count].isfirst = false;
                   if(numCount == true){
	                   var day = ret.ScoreOfYesterday < 0 ? '0' : ret.ScoreOfYesterday
	                   var moth = ret.ScoreOfLastMonth < 0 ? '0' : ret.ScoreOfLastMonth
	                   var tot = ret.TotalScore < 0 ? '0' : ret.TotalScore
	                   $('.q_index_showstatus .day').html(day);
	                   $('.q_index_showstatus .moth').html(moth);
	                   $('.q_index_showstatus .tot').html(tot);
	                   jQuery(document).ready(function($) {
					        $('.counter').counterUp({
					            delay: 100,
					            time: 1200
					        });
					    });
	                   numCount = false;
               		}
            	   var data = _this.getList(count,ret.Detial);
            	   _this.getDetialStyle(data,count);
                }
            });
		},
		getDetialStyle:function(data,count){
			var chart2 = document.getElementById('echart'+count);
   			var echart2= echarts.init(chart2,'customed');
		    var option2 = {
		        tooltip: {
		            trigger: 'axis'
		        },
		        xAxis: {
		            type: 'category',
		            boundaryGap: false,
		            data:data.dateList
		        },
		        yAxis: {
		            type: 'value',
		        },
		        series: [
		            {
		                name:'绩效',
		                type:'line',
		                markPoint: {
		                    data: [
		                        {type: 'max', name: '最大值'},
		                        {type: 'min', name: '最小值'}
		                    ]
		                },
		                data:data.dataList
		            },
		        ]
		    };
		    echart2.setOption(option2);
		},
		getList:function(count,data){
            var dateList = [];
            var dataList = [];
            for(var i = 0; i< count; i++){
                var date = new Date(new Date()- 86400000*i );
                var Year = date.getFullYear();
                var Month = date.getMonth()+1;
                var Month1 = Month < 10 ? '0'+ Month :Month;
                var Day = date.getDate();
                Day = Day < 10 ? '0'+ Day :Day;
                dateList.splice(0, 0, Month1+'-'+Day);

                var TimeStr = Year+'-'+Month1+'-'+Day;
                var timestamp = Date.parse(TimeStr)/100000;
                var Count2 = 0;
                $.each(data,function(k,v){
                    var TimeStr2 = m.formatYmd1(v.Date);
                    var timestamp1 = Date.parse(TimeStr2)/100000;
                    if(timestamp == timestamp1){
                        if(typeof (data[k]) != 'undefined' && data[k].Score){
                            Count2 = data[k].Score;
                        }
                    }
                });
                dataList.splice(0, 0, Count2);
            }
            var JsonData = {
                dateList:dateList,
                dataList:dataList,
            }
           return JsonData;
        }
	}
	var a = new Cont();

})